package xlhfxlh;

import java.io.*;

public class TestSerializable {
    public static void main(String[] args) {
//        method();
        method2();
    }

    public static void method2() {
        ObjectInputStream in = null;
        try{
            in = new ObjectInputStream(new FileInputStream("D://ready//1.txt"));
            Object o = in.readObject();
            System.out.println(o);
            System.out.println("反序列化成功");

        }catch (Exception e){
            System.out.println("反序列化失败");
            e.printStackTrace();
        }finally {
            try{
                in.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }

    public static void method() {
        ObjectOutputStream out = null;
        try{
            out = new ObjectOutputStream(new FileOutputStream("D://ready//1.txt"));
            Student obj = new Student("陈浩南",12,"铜锣湾",'男');
            out.writeObject(obj);
            System.out.println("序列化成功");

        }catch (Exception e){
            System.out.println("序列化失败");
            e.printStackTrace();
        }finally {
            try{
                out.close();
            }catch (IOException e){
                e.printStackTrace();
            }

        }
    }
}
